package org.opens.javaskill.thread.demo.bank;

import java.util.Random;

public class TicketWindow extends Thread {

    // 最大服务数量
    private final static int MAX = 50;

    // 起始号码
    private static int index = 1;

    // 柜台名称
    private final String windowName;

    public TicketWindow(String windowName) {
        this.windowName = windowName;
    }

    @Override
    public void run() {
        Random random = new Random();
        while ( index <= MAX ) {
            System.out.println("柜台: " + windowName + ", 当前的号码是: " + (index++));
            try {
                Thread.sleep(random.nextInt(3) * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }


    public static void main(String[] args) {
        TicketWindow ticketWindow1 = new TicketWindow("窗口1");
        TicketWindow ticketWindow2 = new TicketWindow("窗口2");
        TicketWindow ticketWindow3 = new TicketWindow("窗口3");

        ticketWindow1.start();
        ticketWindow2.start();
        ticketWindow3.start();
    }

}
